#!/user/bin/env python
# -*- coding: utf-8 -*-
"""
@Time   : 2022-01-23 17:12
@Author : LFY
@File   : config.py
"""
from ctypes import c_char_p
import multiprocessing
from typing import Union
import os
import platform

class Config(object):
    POP_TEXT_KEYWORD = ["同意", "授权", "允许", "关闭", 'close', '确定', '好的','我知道了']
    APPLET_ACTIVITY_NAME = 'com.tencent.mm/.plugin.appbrand.ui.AppBrandUI'
    FORM_BUTTON = {"搜索", "提交"}
    SELECTION_MODE = 'DFS'
    DEVICE_ID = "6990f488"

    PHONE_WIDTH = 1080
    PHONE_HEIGHT = 2621
    EXPLORE_TIME = 7200

    def __getitem__(self, key):
        return self.__getattribute__(key)

class WxConfig(Config):
    PLATFORM = 'wx'
    NAVIGATION_ID = "com.tencent.mm:id/ra"
    POP_UPS_ID = {
    # 提示消息 or 打开其他小程序，左边取消
        "com.tencent.mm:id/ffh": ["com.tencent.mm:id/ffb", "com.tencent.mm:id/ffp"],
    # 获取用户信息 or 权限
        "com.tencent.mm:id/h3o": ["com.tencent.mm:id/h3l", "com.tencent.mm:id/h3t"],
    # 点登录确定
        "com.tencent.mm:id/oe": ["com.tencent.mm:id/gui", "com.tencent.mm:id/guw"]
    }
    NATIVE_POP_RESOURCE_ID = ['com.tencent.mm:id/oe', 'com.tencent.mm:id/ipz',
                              'com.tencent.mm:id/ffb']
    TOP_BAR_HEIGHT = 360
    WX_APP_BRAND = '-1'
    # TAG_XPATH = "//*[@data-url or @url] | //wx-button | //wx-view[(text()[normalize-space(.) != ''])] | //span[text()[normalize-space(.) != '']] | //wx-image[@src]"
    TAG_XPATH = [
                "//wx-image[@src]",
                "//*[@data-url or @url]",
                "//wx-button",
                "//wx-view[text()[normalize-space(.) != ''] or .//*[text()[normalize-space(.) != '']]]",
                "//wx-text[text()[normalize-space(.) != ''] or .//*[text()[normalize-space(.) != '']]]",
                "//div[text()[normalize-space(.) != '']]",
                "//button"
            ]


class ZfbConfig(Config):
    PLATFORM = 'zfb'
    NAVIGATION_ID = "com.alibaba.ariver.ariver:id/ariver_tabbar_item_text"
    POP_UPS_ID = {
    # 提示消息 or 打开其他小程序，左边取消
        "com.alipay.mobile.antui:id/message": ["com.alipay.mobile.antui:id/cancel", "com.alipay.mobile.antui:id/ensure"],
    # 获取用户信息 or 权限
        "com.alipay.mobile.antui:id/permission_description": ["com.alipay.mobile.antui:id/cancel",
                                                              "com.alipay.mobile.antui:id/ensure"],
        "com.alipay.mobile.nebulaintegration:id/tiny_permission_description" : ["com.alipay.mobile.nebulaintegration:id/tiny_permission_cancel",
                                                               "com.alipay.mobile.nebulaintegration:id/tiny_permission_ensure"],
    }
    NATIVE_POP_RESOURCE_ID = []

class BdConfig(Config):
    PLATFORM = "bd"
    NAVIGATION_ID = "com.baidu.swan:id/bottom_tab_icon"
    POP_UPS_ID = ["com.baidu.swan:id/positive_button"]
    NATIVE_POP_RESOURCE_ID = ["com.baidu.searchbox:id/obfuscated"]


    TOP_BAR_HEIGHT = 300
    BD_APP_BRAND = '-1'
    TAG_XPATH = [
                "//swan-image[@src]",
                "//*[@data-url or @url]",
                "//swan-button",
                "//swan-view[text()[normalize-space(.) != ''] or .//*[text()[normalize-space(.) != '']]]",
                "//swan-text[text()[normalize-space(.) != ''] or .//*[text()[normalize-space(.) != '']]]",
                "//div[text()[normalize-space(.) != '']]",
                "//button"
            ]


class KAppConfig(Config):
    PLATFORM = "kuai"
    NAVIGATION_ID = "com.baidu.swan:id/bottom_tab_icon"
    POP_UPS_ID = ["com.vivo.hybrid:id/vbutton_title"]
    NATIVE_POP_RESOURCE_ID = ['com.vivo.hybrid:id/parentPanel']


class MiniAppConfig:    
    def __init__(self, manager) -> None:
        self.manager = manager
        # 小程序名 - 国务院
        self.applets_name = manager.Value(c_char_p, "")
        # 小程序页面 - /page/index/index.html?query=111 带参数
        self.pageUrl = manager.Value(c_char_p, "")


INPUT_VALUES = {
    '身份证' : '330682199808273015',
    '证件' : '330682199808273015',
    '手机' : '13366164349',
    '邮箱' : '1284815915@qq.com',
    '姓名' : '王佳清',
    '昵称' : '小王',
    '年龄' : 25,
    '地名' : '上海',
    '地址' : '芳草寓',
    '身高' : '175',
    '学历证书' : '1061 1120 2105 004319',
    '关键词' : "政策",
    '标题' : 'test',
    '名称' : "王佳清",
    '输入' : '测试测试测试',
    '用户名' : 'username123',
    '密码' : 'password123',
    '性别' : '男',
    '工作' : '程序员',
    '爱好' : '篮球',
    '公司' : 'OpenAI',
    '职位' : '数据分析师',
    '个人描述' : '我是一个热爱编程的程序员',
    '毕业学校' : '清华大学',
    '专业' : '计算机科学',
    '毕业年份' : '2020',
    '出生日期' : '1998-08-27',
    '国籍' : '中国',
    '语言' : '汉语',
    '省份' : '浙江省',
    '城市' : '杭州市',
    '区域' : '西湖区',
    '邮编' : '310000',
    'QQ' : '123456789',
    '微信' : 'wechat123',
    '头像URL' : 'https://example.com/profile.jpg',
    '家庭地址' : '浙江省杭州市西湖区',
    '公司地址' : '上海市浦东新区',
    '个人主页' : 'https://example.com'
}

CODE_MODEL = "DEVELOP"
# CODE_MODEL = "PRODUCT"
# 小程序解包 js 工具路径
WX_UNPACK_PATH = os.path.join(os.path.dirname(__file__), "wxUnpack/wuWxapkg.js")

# Select the appropriate ChromeDriver based on platform
if platform.system() == "Windows":
    chromedriverExecutable = os.path.join(os.path.dirname(__file__), "chromeDriver/chromedriver.exe")
else:
    chromedriverExecutable = os.path.join(os.path.dirname(__file__), "chromeDriver/chromedriverMac86")

# wx 8.0.10 小程序存放路径 /data/data/com.tencent.mm/MicroMsg/{{userHash}}/appbrand/pkg/
userHash = "8ad392dbce9a5722e419bfe9227bb819"
# mitm 服务 IP
mitmIP = "127.0.0.1"
# mitmproxy 服务端口
mitmPort = 9999
# mongo 流量数据库名（集合名小程序名
trafficDbName = "traffic"
# mongo 视图数据库名（集合名小程序名
pageDbName = "page"


BUFFER_SIZE = 1024

# 测试时间
MINI_APP_TEST_TIME = 60 * 10

LOG_DICTIONARY_NAME = "threshold_logs"

WEBVIEW_MODE = True
CLIENT_SIDE_CONF = WxConfig()
SELECTION_CONF = WxConfig()
DE_DUPLICATION_CONF = WxConfig()
MINIAPP_CONF = None


# yyt XPOSCOPE
project_prefix = "/tmp"
dynamic_prefix = "/tmp"

MOBILE_IMAGE_PATH = "/sdcard/screenshots/"
SCREENSHOT_PATH = dynamic_prefix + "/data/screenshots/"
EVALUATE_PATH = dynamic_prefix + "/data/evaluate_classifier/"

MOBILE_SCREENSHOT_CACHE_PATH = "/sdcard/picCache/"
SCREENSHOT_CACHE_PATH = dynamic_prefix + "/data/picCache/"

PAGE_TEXT_PATH = dynamic_prefix + "/data/page_text/"
MINI_APP_LOG = project_prefix + "/MiniAppLog/"